<template>
  <el-cascader
    :show-all-levels="false"
    :options="tree"
    :props="{ value:'id',label:'name'}"
    v-model="val"
    :disabled="disabled"
    @change="$emit('change',$event)"
  />
</template>
<script>
// import name from "./name";
export default {
  // components: { name},
  // props: ["data", "disabled"],
  props: {
    data: { default: "" },
    disabled: { default: false },
    list: { default: false }
  },
  watch: {
    data() {
      this.setTree();
    }
  },
  data() {
    return {
      tree: [],
      val: []
    };
  },
  // computed() {return{}},
  created() {
    this.setTree();
  },
  methods: {
    setTree() {
      if (!this.list) this.list = this.$gd.project;
      this.tree = this.list.arr2tree();
      if (this.data) {
        let d = this.$cp(this.data);
        if (typeof d == "number" || typeof d == "string") {
          this.val = this.list.getTreeID(Number(d));
        } else this.val = d;
      }
    }
  }
};
</script>

<style scoped>
</style>
